<!-- 最近阅读 -->
<script setup lang="ts">
import { getBookInfo, getMenu } from '@/api/getAxios';
import { ref } from 'vue';

const data = defineProps({
    data: Object
})
const bookitem = ref()
const index = ref()
const speed = ref()
const showBottom = ref(false)
const showBook = ref(true)
getBookInfo(<any>(data.data?.id)).then((res) => {
    bookitem.value = res.data.data
    let speed = JSON.parse(<any>localStorage.getItem("speed"))
    index.value = speed[speed.findIndex((val: any) => val.id == bookitem.value.id)].target
})
getMenu(data.data?.id).then((res) => {
    speed.value = res.data.data.chapterList[index.value].name
})
</script>
<template>
    <div class="main" v-if="showBook">
        <div v-if="bookitem" class="item" @click="$router.push({ path: '/BookInfo', query: { storyId: bookitem.id } })">
            <p><img :src="bookitem.cover" alt=""></p>
            <div class="message">
                <p>{{ bookitem.name }}</p>
                <p>{{ bookitem.authorName }}</p>
                <p>观看至 {{ speed }}</p>
                <p>{{ data.data?.time }}</p>
            </div>
        </div>
    </div>
</template>

<style scoped lang='less'>
.item {
    margin: 10px 0;
    display: flex;
    background-color: white;
    border-radius: 8px;
    padding: 10px;
    transition: all 0.2s;

    &:active {
        background-color: whitesmoke;
    }

    >p:nth-child(1) {
        width: 22%;
        border-radius: 8px;
        overflow: hidden;
        margin-right: 10px;

        img {
            width: 100%;
            border-radius: 8px;
        }
    }

    .message {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        flex: 1;

        p:nth-child(1) {
            font-size: 1rem;
            color: black;
        }

        p {
            font-size: .9rem;
            color: #605f5f;
        }

        p:last-child {
            font-size: .85rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        button {
            background-color: white;
            border: 0;
            width: 38px;

            img {
                width: 100%;
            }
        }
    }
}
</style>